﻿using System.Collections.Generic;
using System.Web.Mvc;
using AutoMapper;
using good1.ApplicationServices.Dto;
using good1.ApplicationServices.Interface;
using good1.Core;
using good1.Web.Controllers.Filters;
using good1.Web.Controllers.Infrastructure;
using good1.Web.Controllers.Infrastructure.Cookies;
using good1.Web.Model;
using SharpArch.Core;

namespace good1.Web.Controllers
{
    public class HomeController : BaseController
    {
 
        public HomeController(IProjectService<ProjectDto> projectService ,ISecurityContextService securityContext): base(securityContext)
        {
            Check.Require(projectService != null, "projectService may not be null");
            this.projectService = projectService;

        }


        [CompressFilter]
        public ActionResult Index()
        {
            //TODO if performance is bottlenecking here, we might look at caching the GetFeatured call.
            //to do this well we'd want to look at the slider control which is already output cached
            //also consider the second level nhibernate caching as a potentially very rich gain.
            //all that said we need some clear performance results and set universal gains that could be made for this effort.
            //tread carefully with caching.
            //reference to partial caching of controls
            //http://haacked.com/archive/2009/05/12/donut-hole-caching.aspx
            ProjectListView projectListView = CreateViewData<ProjectListView>();
            IList<Project> projects = projectService.GetFeatured();
            Mapper.CreateMap<Project, ProjectListItem>();
            projectListView.ProjectList = Mapper.Map<IList<Project>, IList<ProjectListItem>>(projects); ;
            return View(projectListView);
        }

        private readonly IProjectService<ProjectDto> projectService;

    }
}
